package com.dliu.javacore.enumFeature;

import com.dliu.javacore.enumFeature.vo.People;

/**
 * 使用枚举实现单例
 * @author yanglei
 * date 2021/3/25 18:35
 */
public enum Singleton {
    INSTANCE;

    private final People people;

    Singleton(){
        people = new People();
    }
    public People getInstance(){
        return people;
    }

    public static void main(String[] args) {
        //观察对象地址
        People instance1 = Singleton.INSTANCE.getInstance();
        People instance2 = Singleton.INSTANCE.getInstance();
        System.out.println(instance1.hashCode());
        System.out.println(instance2.hashCode());
    }
}
